package edu.pku.sei.transformation.editor.controller.commands.node;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.transformation.editor.model.Domain;
import edu.pku.sei.transformation.editor.model.DomainConnection;
import edu.pku.sei.transformation.editor.model.Rule;

public class DomainCreateCommand extends Command {
	private Rule relation;
	private Domain domain;
	private DomainConnection relaCon;

	public DomainCreateCommand(Rule relation, Domain domain) {
		this.relation = relation;
		this.domain = domain;
	}

	@Override
	public boolean canExecute() {
		if (this.relation != null && this.domain != null)
			return true;
		else
			return false;
	}

	@Override
	public void execute() {
		this.relation.getDomains().add(this.domain);
		this.domain.setOwner(this.relation);
	}

	@Override
	public void redo() {
		this.relation.getDomains().add(this.domain);
		this.domain.setOwner(this.relation);
	}

	@Override
	public void undo() {
		this.relation.getDomains().remove(this.domain);
		this.domain.setOwner(null);
	}
}
